<template>
    <div class="container">
        <addMedicalDepartment ref="addMedicalDepartment" />
        <officerTeacher ref="officerTeacher" />
        <PersonnelList ref="PersonnelList" />
        <baseTeacherDepartmentList ref="baseTeacherDepartmentList" />

        <div class="main">
            <div class="header felx">
                <div class="header_l flex">
                    <div class="header_btn flex" @click="addHandle" style="margin-right: 20px;">
                        <img src="../../assets/room_add_icon.png" style="width: 13px;height: 13px;margin-right: 0;" />
                        <p>添加处室</p>
                    </div>
                    <!-- <div class="flex" style="cursor: pointer;margin-right: 15px;"
                        v-loading.fullscreen.lock="fullscreenLoading" @click="importHandle">
                        <img src="../../assets/fileFlow_add.png">
                        <p>批量导入</p>
                        <el-icon>
                            <ArrowDown />
                        </el-icon>
                    </div> -->
                    <!-- <div class="flex" style="cursor: pointer;" v-loading.fullscreen.lock="fullscreenLoading"
                        @click="exportHandle">
                        <img src="../../assets/fileFlow_add.png">
                        <p>导出报表</p>
                    </div> -->
                </div>
                <div class="header_r flex">

                    <div class="serachBox flex">
                        <div class="flex">
                            <p style="width: 60px;">处室名称</p>
                        </div>

                        <input type="text" v-model="searchValue" @keyup.enter="searchEnter">
                        <button style="padding: 0 10px;" @click="getList">搜索</button>
                    </div>
                </div>
            </div>
            <div class="borderBox">

                <div class="table_box">
                    <el-table :data="list" border style="width: 100%;" scrollTo :row-class-name="tableRowClassName"
                        :header-cell-style="headerCellStyle" :row-style="tableRowStyle">
                        <el-table-column type="index" label="序号" width="120">
                            <template #header>
                                <div class="header_icon">
                                    <span>序号</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="处室名称">
                            <template #header>
                                <div class="header_icon">
                                    <span>处室名称</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="leader2Name" label="中心主任">
                            <template #header>
                                <div class="header_icon">
                                    <span>中心主任</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="leader3Name" label="主管校长">
                            <template #header>
                                <div class="header_icon">
                                    <span>主管校长</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="leader4Name" label="校区校长">
                            <template #header>
                                <div class="header_icon">
                                    <span>校区校长</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column> -->

                        <el-table-column label="操作" fixed="right">
                            <template style="display: block" #default="scope">
                                <el-button class='edit_btn' size="small" type="primary"
                                    @click="baseTeacherDepartmentList1(scope.row)">人员列表
                                </el-button>
                                 <!--
                                <el-button class='edit_btn' size="small" type="warning"
                                    @click="editBaseDepartmentManager(scope.row)">主管人员
                                </el-button> -->
                                <el-button class="edit_btn" size="small" type="success" style="margin-right: 10px;"
                                    @click="editHandle(scope.row.id)">编辑
                                </el-button>
                                <el-button class="del_btn" size="small" type="danger"
                                    @click="delHandle(scope.row.id)">删除
                                </el-button>
                            </template>
                        </el-table-column>



                    </el-table>
                </div>

                <el-config-provider :locale="locale">
                    <div style="margin-top: 10px" class="pageBox flex">
                        <el-pagination :total="total" :current-page="page" :page-size="pageSize" background
                            layout="prev, pager, next, sizes" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            @size-change="changePageSize" @current-change="changeCurrentPage" />
                        <div class="flex">
                            <p>第 {{ page }} 条</p>
                            <p>共 {{ total }} 条数据</p>
                        </div>
                    </div>
                </el-config-provider>
            </div>
        </div>
    </div>
</template>
<script>
import { httpService } from "@/utils/httpService";
import { formatTime } from "@/utils/dateFormat";
import { ElConfigProvider, ElMessage, ElMessageBox, ElLoading } from "element-plus";
import { MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown } from "@element-plus/icons-vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import addMedicalDepartment from "../../components/medicalProduct/addMedicalDepartment.vue"
import officerTeacher from "../../components/medicalProduct/officerTeacher.vue"
import PersonnelList from "../../components/medicalProduct/PersonnelList.vue"
import baseTeacherDepartmentList from "@/components/baseInfo/baseTeacherDepartmentList.vue";

export default {
    name: "MedicalProductLogin",
    components: {
        ElMessage, MoreFilled, ElLoading, ElMessageBox, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold,
        ArrowDown, ElConfigProvider, addMedicalDepartment, officerTeacher, PersonnelList, baseTeacherDepartmentList,
    },
    data() {
        return {
            page: 1,
            pageSize: 10,
            total: 0,
            list: [],
            fullscreenLoading: false,
            searchTitle: "搜索条件",
            searchValue: "",
            selectData: {},
            mobileNumber: "",
        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    computed: {},
    mounted() {
        this.getList()
    },
    methods: {
        searchEnter: function (e) {
            console.log(e);
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getList();
            }
        },
        tableRowClassName({ row, rowIndex }) {
            // console.log(rowIndex);
            return rowIndex % 2 === 1 ? 'warning-row' : '';
        },
        headerCellStyle() {
            return {
                background: '#f2f2f2',
            };
        },
        tableRowStyle({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return {
                    background: '#F5F5F5',
                };
            }
        },
        reload() {
            this.getList()
        },
        changePageSize(size) {
            this.pageSize = size;
            this.getList();
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getList();
        },
        addHandle() {
            this.$refs.addMedicalDepartment.flag = true
            this.$refs.addMedicalDepartment.title = "添加处室"
        },

        resetHandle(id) {
            this.$refs.resetPassward.flag = true
            this.$refs.resetPassward.form.id = id
        },
        editHandle(id) {
            // this.$refs.addMedicalProductUser.flag = true
            // this.$refs.addMedicalProductUser.queryById(id)

            this.$refs.addMedicalDepartment.flag = true
            this.$refs.addMedicalDepartment.title = "修改处室"
            this.$refs.addMedicalDepartment.queryById(id)
        },
        importHandle(id) {
            this.$refs.importFileView.flag = true
            this.$refs.importFileView.url = "/javaApi/materials/importExcel"
        },
        selectHandle(value) {
            console.log(value);
            this.searchTitle = value
        },

        getMobile(data) {
            this.selectData = data
            this.mobileNumber = ''
            this.getBasedecrypt(this.selectData)
        },
        editBaseDepartmentManager(obj) {
            // alert(JSON.stringify(obj))
            this.$refs.officerTeacher.title = "主管人员";
            // this.$refs.officerTeacher.name = this.name;
            // this.$refs.officerTeacher.type = this.type;
            this.$refs.officerTeacher.getBaseTeacherListApp();
            this.$refs.officerTeacher.getBaseDepartmentById(obj.id);
            this.$refs.officerTeacher.flag = true;
        },
        baseTeacherDepartmentList1(obj) {
            this.$refs.baseTeacherDepartmentList.title = obj.name;
            this.$refs.baseTeacherDepartmentList.getBaseTeacherDepartmentList(obj.id);
            this.$refs.baseTeacherDepartmentList.dialogFormVisible = true;
            this.$refs.baseTeacherDepartmentList.type = this.type;
        },
        getList() {
            httpService(
                "/javaApi/baseDepartment/list/" + this.page + "/" + this.pageSize,
                {
                    type: 1,
                    noCampus: 1,
                    name: this.searchValue,
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
            });
        },

        delHandle(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService(
                        "/javaApi/baseDepartment/deleteById", "id=" + id, "post"
                    ).then((data) => {
                        if (data.code == 200) {
                            ElMessage.success("删除成功");
                            this.getList()
                        } else {
                            ElMessage.error("删除失败，请重试！");
                        }
                    });
                })
                .catch(() => { });
        },

    },
};
</script>
<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.container {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    padding: 15px 15px;
    background-color: #EEF7FB;
}

.main {
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
}

.header {
    height: 45px;
    /* background-color: chocolate; */
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header_btn {
    width: 99px;
    height: 32px;
    background-color: #6F72FF;
    border-radius: 5px;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    margin-right: 15px;
    cursor: pointer;
}

.header_btn img {
    width: 17px;
    height: 18px;
    margin-right: 5px;
}

.serachBox {
    color: #666666;
    font-size: 14px;
    width: 340px;
    height: 36px;
    border: 1px solid #D0D0D0;
    box-sizing: border-box;
    border-radius: 20px;
}

.serachBox .flex {
    justify-content: center;
    border-right: 1px solid #D0D0D0;
    margin-right: 10px;
    padding: 0 5px 0 15px;
    color: #666666;
    cursor: pointer;
}

.serachBox input {
    height: calc(100% - 4px);
    border: none;
    flex: 1;
    outline: none;
}

.serachBox button {
    width: 80px !important;
    height: 30px;
    border-radius: 15px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-right: 2px;
    outline: none;
}


.borderBox {
    height: calc(100% - 60px);
    border: 1px solid #DFDFDF;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 15px;
}

.borderTop {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.assetsNum {
    margin-left: 20px;
    color: #666666;
    font-size: 14px;
}

.borderTop .flex {
    margin-right: 20px;
}

.borderTop_btn {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #666666;
    margin-left: 40px;
    cursor: pointer;
}

.header_icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table_box {
    width: calc(100vw - 283px);
    height: calc(100% - 53px);
    /* background-color: slategrey; */
    overflow-y: auto;
}

.el-table {
    /* margin-left: -1px; */
}

.rotate {
    transform: rotate(90deg);
}


.el-scrollbar__bar {
    z-index: 11;
    overflow-x: hidden;
    position: sticky;
}

.el-table.el-table--border {
    overflow: unset;
}


.pageBox {
    background-color: #f6f6f6;
    padding: 5px 0;
    border-top: 1px solid #e7e7e7;
    border-radius: 0 0 5px 5px;
}

.el-pagination {
    margin-left: 10px;
}

.pageBox {
    justify-content: space-between;
}

.pageBox .flex {
    color: #666;
    font-size: 14px;
    margin-right: 10px;
}

.pageBox .flex p {
    color: #666;
    font-size: 14px;
    margin-right: 20px;
}

.edit_btn {
    background-color: transparent;
    color: #007EFF;
    border: none;
    margin-right: 10px;
}

.del_btn {
    background-color: transparent;
    color: #FF0000;
    border: none;
}

.retire_btn {
    background-color: transparent;
    border: none;
    color: #007EFF;
}

.face_btn {
    background-color: transparent;
    color: #ff8400;
    border: none;
}

.header_l .flex p {
    margin: 0 5px;
}

.el-tooltip__trigger:focus-visible {
    outline: unset;
}
</style>